package br.ufrj.dcc.traffictip.http;

import java.util.Enumeration;
import java.util.Hashtable;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.htmlparser.util.NodeList;

import br.ufrj.dcc.traffictip.helper.HtmlParser;

@Path("/")
public class TrafficStatus
{

	@GET
	@Produces("application/json")
	@Path("status")
	public String Status()
	{

		HtmlParser htmlparser = new HtmlParser();
		NodeList list = htmlparser.getBoletimList();
		
		Hashtable<String, String> hash = htmlparser.extractData(list);
		
		Enumeration<String> keys = hash.keys();
		StringBuilder sb = new StringBuilder("{\"status\": { ");

		while(keys.hasMoreElements())
		{
			String street = keys.nextElement();
			String color =  hash.get(street);
			sb.append("\"" + street + "\" : \"" + color + "\", ");
		}
		
		sb.replace(sb.length()-2,sb.length()-1, "");
		
		sb.append("} }");
		
		return sb.toString();
	}
}
